package com.kaidongyuan.app.kdydriverr.serviceAndReceiver;

import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class CameraManager implements SurfaceHolder.Callback {
    private Camera mCamera;
//    private SurfaceView mSurfaceView;
//    private SurfaceHolder mSurfaceHolder;

    public CameraManager(Context context, SurfaceView surfaceView) {
//        mSurfaceView = surfaceView;
//        mSurfaceHolder = mSurfaceView.getHolder();
//        mSurfaceHolder.addCallback(this);
    }

    public void openCamera() {
        mCamera = Camera.open();
    }

    public void startPreview() {
//        try {
//            mCamera.setPreviewDisplay(mSurfaceHolder);
            mCamera.startPreview();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
    }

    public void takePicture(Camera.PictureCallback callback) {
        mCamera.takePicture(null, null, callback);
    }

    public void releaseCamera() {
        mCamera.release();
        mCamera = null;
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        openCamera();
//        startPreview();
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        // Implement if needed
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        releaseCamera();
    }
}
